package com.xyht.medicine_management_system.modules.user.controller;


import com.xyht.medicine_management_system.auth.util.JwtTokenUtil;
import com.xyht.medicine_management_system.common.commonReturn.ResponseResult;
import com.xyht.medicine_management_system.common.desEncodeAndDecode.annotation.SecretBody;
import com.xyht.medicine_management_system.modules.user.entity.req.AuthReq;
import com.xyht.medicine_management_system.modules.user.service.AuthorizationService;
import io.swagger.annotations.ApiModelProperty;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import javax.servlet.http.HttpServletRequest;

/**
 * <p>
 * 应用列表 前端控制器
 * </p>
 *
 * @author XYHT
 * @since 2023-12-18
 */
@RestController
@RequestMapping("/auth")
@SecretBody
public class AuthorizationController {
    @Resource
    private AuthorizationService authorizationService;
    @Resource
    private JwtTokenUtil jwtTokenUtil;

    @GetMapping("/userAppList")
    @ApiModelProperty(value = "用户可用应用列表")
    public ResponseResult userUseGetAppList(HttpServletRequest request){
        String user_id = jwtTokenUtil.getUserIdByRequest(request);
        return authorizationService.userUseGetAppList(user_id);
    }

    @GetMapping("/checkPermission")
    @ApiModelProperty(value = "校验用户权限")
    public ResponseResult isAppPermission(@RequestParam("requestPath")String requestPath,
                                          HttpServletRequest request){
        return authorizationService.isAppPermission(requestPath,request);
    }

    @GetMapping("/roleAuthList")
    @ApiModelProperty(value = "获取角色拥有权限列表")
    public ResponseResult getAuthList(@RequestParam("roleId")String roleId){
        return authorizationService.getAuthList(roleId);
    }

    @PostMapping("/roleAuthUpdate")
    @ApiModelProperty(value = "修改角色权限")
    public ResponseResult updateApplication(@RequestBody AuthReq authReq){
        return authorizationService.updateApplication(authReq);
    }

}

